import 'package:flutter/animation.dart';
import 'package:get/get.dart';
import 'dart:async';
import 'package:meco/common/index.dart';

class StartController extends GetxController
    with GetSingleTickerProviderStateMixin {
  StartController();

  // 动画控制器
  late AnimationController logoAnimationController;
  late Animation<double> logoAnimation;
  late Animation<double> fadeInAnimation;
  late Animation<double> scaleAnimation;

  final RxBool animationCompleted = false.obs;

  @override
  void onInit() {
    super.onInit();

    // 初始化动画控制器
    logoAnimationController = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 2500),
    );

    // Logo出现动画（从小到大）
    logoAnimation = Tween<double>(begin: 0, end: 1).animate(
      CurvedAnimation(
        parent: logoAnimationController,
        curve: const Interval(0.0, 0.5, curve: Curves.easeOut),
      ),
    );

    // 淡入动画
    fadeInAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(
        parent: logoAnimationController,
        curve: const Interval(0.5, 0.8, curve: Curves.easeIn),
      ),
    );

    // 缩放动画
    scaleAnimation = Tween<double>(begin: 1.0, end: 1.15).animate(
      CurvedAnimation(
        parent: logoAnimationController,
        curve: const Interval(0.8, 1.0, curve: Curves.easeInOut),
      ),
    );
  }

  _initData() {
    // 启动动画
    logoAnimationController.forward();

    // 3秒后跳转到主页
    Timer(const Duration(milliseconds: 3300), () {
      Get.offAllNamed(Routes.main);
    });

    update(["start"]);
  }

  void onTap() {}

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  @override
  void onClose() {
    logoAnimationController.dispose();
    super.onClose();
  }
}
